/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.fjut.se1603.mybatis.service.impl;

import com.github.pagehelper.PageHelper;
import edu.fjut.se1603.mybatis.dao.SysUserDao;
import edu.fjut.se1603.mybatis.entity.SysUser;
import edu.fjut.se1603.mybatis.service.UserService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author danny
 */
@Service
@Transactional(readOnly = true)
public class UserServiceImpl implements UserService {
    
    @Autowired
    SysUserDao dao;

    @Override
    public List<SysUser> getUsersWithPagination(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SysUser> select = dao.select();
        return select;
    }

    @Override
    @Transactional
    public boolean modifyUser(SysUser user) {
        return dao.update(user) == 1 ? true : false;
    }

    @Override
    public SysUser getUserById(int id) {
        return dao.selectByPrimaryKey(id);
    }

    @Override
    @Transactional
    public boolean addUser(SysUser user) {
        return dao.insert(user) == 1 ? true : false;
    }

    @Override
    public List<SysUser> queryList(SysUser user) {
        return dao.selectByExample(user);
    }
    
}
